﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DotNetDream.WebMetroEngine.Mvc.Context;
using DotNetDream.WebMetroEngine.Mvc.Models;

namespace DotNetDream.WebMetroEngine.Mvc.Repository
{
    public class ModuleRepository : DotNetDream.Data.Helper.EntityFramework.RepositoryBase<ModuleContext>
    {
        /// <summary>
        /// Get the list of specific domain filter by module name
        /// </summary>
        /// <param name="domainId"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        public DomainModules GetDomainModule(int domainId, string filter)
        {
            var modules = Select<Domain>(d => d.Id == domainId)
                .FirstOrDefault()
                .Modules
                .Where(m => m.IsActive && m.Name.Contains(filter)).ToList();

            return new DomainModules { DomainId = domainId, ModuleNameFilter = filter, Modules = modules };
        }
    }
}
